package com.mindai.esper.monitor.biz.epl;

import com.espertech.esper.client.EventBean;
import com.espertech.esper.client.EventType;
import com.espertech.esper.client.UpdateListener;
import com.mindai.esper.monitor.biz.domain.model.EsperEplModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * Created by Ladd on 16-7-26.
 */
@Data
@AllArgsConstructor
@Slf4j
public class EsperEplListener implements UpdateListener {

    private EsperEplModel esperEplModel;

    @Override
    public void update(EventBean[] newEvents, EventBean[] oldEvents) {
        if (newEvents != null) {
            EventType eventType = newEvents[0].getEventType();
            String outputStreamName = eventType.getName();
            Map<String, Object> statisticEvent = (Map<String, Object>) newEvents[0].getUnderlying();
            log.info("EsperEplListener:////outputStreamName:{},map={}", outputStreamName, statisticEvent);
//            if(epl.isAlarm()) collector.emit(new Values(outputStreamName, statisticEvent));
//            DBUtils.insertTriggerRecord(this.epl.getId(), this.epl.getEplName(), statisticEvent);
        }
    }
}
